From 240ed1a3e505c32d6ac7bddea9a386c730e8f218 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 19 Dec 2014 13:43:21 -0800 Subject: [PATCH] Fix cases where a registry is not updated If a registry already knew about a package, but didn't know about newly published version of a package, then the registry would occasionally not be updated when it otherwise needed to be. --- src/cargo/sources/registry.rs | 10 ++++++--- tests/test_cargo_registry.rs | 40 +++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/cargo/sources/registry.rs b/src/cargo/sources/registry.rs index 4dabec727..6566b88fb 100644 --- a/src/cargo/sources/registry.rs +++ b/src/cargo/sources/registry.rs @@ -464,9 +464,13 @@ impl<'a, 'b> Registry for RegistrySource<'a, 'b> { // theory the registry is known to contain this version. If, however, we // come back with no summaries, then our registry may need to be // updated, so we fall back to performing a lazy update. - if dep.get_source_id().get_precise().is_some() && - try!(self.summaries(dep.get_name())).len() == 0 { - try!(self.do_update()); + if dep.get_source_id().get_precise().is_some() { + let mut summaries = try!(self.summaries(dep.get_name())).iter().map(|s| { + s.0.clone() + }).collect::>(); + if try!(summaries.query(dep)).len() == 0 { + try!(self.do_update()); + } } let summaries = try!(self.summaries(dep.get_name())); diff --git a/tests/test_cargo_registry.rs b/tests/test_cargo_registry.rs index bd3dcbb8d..2b4792359 100644 --- a/tests/test_cargo_registry.rs +++ b/tests/test_cargo_registry.rs @@ -610,3 +610,43 @@ test!(git_and_registry_dep { assert_that(p.process(cargo_dir().join("cargo")).arg("build"), execs().with_status(0).with_stdout("")); }) + +test!(update_publish_then_update { + let p = project("foo") + .file("Cargo.toml", r#" + [project] + name = "foo" + version = "0.5.0" + authors = [] + + [dependencies] + a = "0.1.0" + "#) + .file("src/main.rs", "fn main() {}"); + p.build(); + + r::mock_pkg("a", "0.1.0", &[]); + + assert_that(p.process(cargo_dir().join("cargo")).arg("build"), + execs().with_status(0)); + + + r::mock_pkg("a", "0.1.1", &[]); + + let lock = p.root().join("Cargo.lock"); + let s = File::open(&lock).unwrap().read_to_string().unwrap(); + File::create(&lock).unwrap().write_str(s.replace("0.1.0", "0.1.1").as_slice()) + .unwrap(); + println!("second"); + + fs::rmdir_recursive(&p.root().join("target")).unwrap(); + assert_that(p.process(cargo_dir().join("cargo")).arg("build"), + execs().with_status(0).with_stdout(format!("\ +{updating} [..] +{downloading} a v0.1.1 (registry file://[..]) +{compiling} a v0.1.1 (registry [..]) +{compiling} foo v0.5.0 ({dir}) +", updating = UPDATING, downloading = DOWNLOADING, compiling = COMPILING, + dir = p.url()).as_slice())); + +}) -- 2.30.2